/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import util.DwConfiguration;
import util.GridConf;

/**
 *
 * @author Dragan
 */
public class MultipleRunsISDC {

    static final int POPULATION_SIZE = 20;
    static final int EVOLUTIONS_COUNT = 200;
    static final int TEST_COUNT = 5;
    static final double RHO = 0.12;

    public static void evolve(DwConfiguration conf) throws Exception {
        String startClause = "MultipleRuns " + new Date();
        String filename = "isdc/" + startClause.replace(":", "-") + ".txt";
        String log = startClause + "\n\n";
        String summary = "SUMMARY:\n";

        List<QE_Evolve> evolveTests = new ArrayList<QE_Evolve>();
        for (int i = 1; i <= TEST_COUNT; i++) {
            String domainFileName = "isdc/domain" + "_Pop=" + POPULATION_SIZE + "_" + conf.getAllowedMaintenanceCost() + "_" + RHO + "_" + i + ".txt";
            String testName = "Test_" + conf.getAllowedMaintenanceCost() + "_" + RHO + "_" + i;
            evolveTests.add(new QE_Evolve(testName, EVOLUTIONS_COUNT, POPULATION_SIZE, domainFileName, conf));
        }
        for (QE_Evolve qe : evolveTests) {
            log += qe.getLog();
            summary += qe.getSummary() + "\n";
        }
        saveText(filename, summary + "\n" + log);
    }

    public static void saveText(String filename, String text) {
        try {
            PrintStream out = new PrintStream(new FileOutputStream(filename));
            out.print(text);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
        evolve(GridConf.getDwConfiguration());
    }
}

